package com.zang.schema.observable.action;

import com.zang.schema.observable.observer.Ditto;
import com.zang.schema.observable.observer.WuZang;
import com.zang.schema.observable.observer.XiaoCiLang;
import com.zang.schema.observable.rate.*;
import com.zang.schema.observable.ring.RingSource;
import com.zang.schema.observable.ring.Student;
import com.zang.schema.observable.ring.Teacher;
import com.zang.test.JdkTest;

/**
 * 观察者模式
 * https://www.cnblogs.com/ae6623/p/4416376.html
 * http://c.biancheng.net/view/1390.html
 *
 * @author Zhang Qiang
 * @Date 2019/8/27 11:52
 */
public class Action {

    public static void main(String[] args) {

        new Action().ditto("abo");

        new Action().rate();
        new Action().ring(true);

    }

    public void ditto(String dt){
        Ditto ditto = new Ditto();

        // 添加观察者（依赖）
        ditto.addObserver(new WuZang());
        ditto.addObserver(new XiaoCiLang());

        // 事件发生
        ditto.setTransformation(dt);
    }

    public void rate(){
        Rate rate = new RMBRate();
        Company importCompany = new ImportCompany();
        Company exportCompany = new ExportCompany();
        rate.add(importCompany);
        rate.add(exportCompany);
        rate.change(-10);
        rate.change(3);
    }

    public void ring(boolean sound){
        RingSource ringSource = new RingSource();
        ringSource.addListener(new Teacher());
        ringSource.addListener(new Student());
        ringSource.ringEvent(sound);
    }

}
